package edu.joe.demo.component;

import component.DaoComponent;
import dao.*;
import edu.joe.demo.conventer.MibDbNodeConverter;
import edu.joe.demo.entity.MibDbNode;
import edu.joe.demo.mapper.*;
import model.MibNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class DbDaoComponent extends DaoComponent {
    @Autowired
    private MibNodeMapper nodeMapper;
    @Autowired
    private MibModuleMapper moduleMapper;

    public class MibDbDao implements IMibNodeDao, IMibModuleDao{
        @Override
        public List<MibNode> getByModuleName(String moduleName) {
            List<MibDbNode> list = nodeMapper.getByModuleName(moduleName);
            return nodeConverter.toBeans(list);
        }
        @Override
        public boolean isModuleExist(String moduleName) {
            return moduleMapper.isModuleExist(moduleName) > 0;
        }
    }

    private MibDbNodeConverter nodeConverter = new MibDbNodeConverter();
    public DbDaoComponent() {
        MibDbDao dao = new MibDbDao();
        this.moduleDao = dao;
        this.nodeDao = dao;
    }
}